package table

import (
	"context"
	"time"

	"go-weixin/app/usercenter/api/internal/svc"
	"go-weixin/app/usercenter/api/internal/types"
	"go-weixin/app/usercenter/rpc/pb/proto/usercenter"

	"github.com/zeromicro/go-zero/core/logx"
)

type TableUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewTableUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TableUpdateLogic {
	return &TableUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *TableUpdateLogic) TableUpdate(req *types.TableUpdateReq) (resp *types.TableUpdateResp, err error) {
	ctx, canelFunc := context.WithTimeout(context.Background(), 5*time.Second)
	defer canelFunc()
	_, err = l.svcCtx.UserRpc.TableUpdate(ctx, &usercenter.TableUpdateReq{
		Id:     req.Id,
		Name:   req.Name,
		Method: req.Method,
		Url:    req.Url,
	})

	return
}
